home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / ACTLIB.ZIP / TOOLS.ZIP / PASSWD.C < prev    next >
C/C++ Source or Header  |  1993-07-28  |  1KB  |  57 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "key.h"
  4. #include "tools.h"
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9.  
  10.  
  11. /*
  12.  * Functions    : getPasswd
  13.  *
  14.  * Description  : Input a password (echoes '*')
  15.  *
  16.  * Parameters   : in  char *passwd    string to store password
  17.  *
  18.  * Remarks      : Backspace and left arrow can be used to erase characters
  19.  *                Characters must be in the range 32 - 254
  20.  *
  21.  * Return       : pointer to password
  22.  *
  23.  */
  24.  
  25. char *getPasswd( char *passwd )
  26. {
  27.  unsigned char *ptr = (unsigned char *)passwd;
  28.  int key;
  29.  
  30.  for (;;)
  31.     {
  32.      switch( key = getkey() )
  33.      {
  34.       case '\0':
  35.       case '\n':
  36.       case '\r':
  37.       case EOF : putch( '\r' ); putch( '\n' );
  38.                  *ptr = '\0';
  39.                  return passwd;
  40.  
  41.       case LEFT:
  42.       case '\b': if ( ptr > (unsigned char *)passwd )
  43.                     {
  44.                      ptr--;
  45.                      putch( '\b' );  putch( SPACE ); putch( '\b' );
  46.                     }
  47.                  continue;
  48.  
  49.       default  : if ( key < 32 || key > 254 ) continue;
  50.  
  51.                  putch( '*' );
  52.      }
  53.  
  54.      *ptr++ = (unsigned char)key;
  55.  }
  56. }
  57.